package main

import (
	"encoding/json"
	"fmt"
	"github.com/mitchellh/mapstructure"
	"reflect"
)

type P struct {
	Name string
	Age  int
}

type Pro struct {
	Type string
	Body interface{}
}

func main() {
	pro1 := `{"type":"123","body":{"name":"11122","age":3}}`
	pro2 := `{"type":"123","body":[{"name":"11122","age":3},{"name":"2222","age":3}]}`

	var pro Pro
	json.Unmarshal([]byte(pro1), &pro)
	fmt.Println("*************", pro)

	var body1 P
	err := mapstructure.Decode(pro.Body, &body1)
	fmt.Println("*************", err)
	var pros2 Pro
	json.Unmarshal([]byte(pro2), &pros2)
	fmt.Println("*************", pros2)
	var body2 []P
	err = mapstructure.Decode(pros2.Body, &body2)
	fmt.Println("*************", err)
	fmt.Println(reflect.TypeOf(pros2.Body).Kind())
	if reflect.TypeOf(pros2.Body).Kind() == reflect.Slice {
		fmt.Println("*****is array********")
	}

}
